<template>
  <el-container style="padding: 15px">
    <el-header height="120px">
      <el-form size="small" label-width="70px">
        <el-row type="flex" :gutter="20" align="middle">
          <el-col :span="6">
            <el-form-item label="报告文号">
              <el-input v-model="searchObj.reportId" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="报告名称">
              <el-input v-model="searchObj.reportName" />
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <el-form-item label="出具日期">
              <el-date-picker
                v-model="searchObj.provideStartTime"
                value-format="timestamp"
                type="date"
                placeholder="开始时间"
                @change="startTimeChangeHandler"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label=" ">
              <el-date-picker
                v-model="searchObj.provideEndTime"
                value-format="timestamp"
                type="date"
                placeholder="结束时间"
                @change="EndTimeChangeHandler"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex" align="middle" :gutter="20">
          <el-col :span="6">
            <el-form-item label="技术人员">
              <el-select v-model="searchObj.technician" style="width: 100%" clearable filterable>
                <el-option v-for="item in users" :key="item.id" :value="item.id" :label="item.nickName" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="业务人员">
              <el-select v-model="searchObj.salesman" style="width: 100%" clearable filterable>
                <el-option v-for="item in users" :key="item.id" :value="item.id" :label="item.nickName" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <el-form-item label="评估日期">
              <el-date-picker
                v-model="searchObj.startTime"
                value-format="timestamp"
                type="date"
                placeholder="开始时间"
                @change="startTimeChangeHandler"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label=" ">
              <el-date-picker
                v-model="searchObj.endTime"
                value-format="timestamp"
                type="date"
                placeholder="结束时间"
                @change="EndTimeChangeHandler"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex" align="center" justify="center">
          <el-col :span="4">
            <el-button type="primary" size="small" @click="getPropertyList">搜索</el-button>
            <el-button size="small" @click="clearSearch">重置</el-button>
          </el-col>
        </el-row>
      </el-form>
    </el-header>
    <el-divider />
    <el-main>
      <el-table :data="propertyList">
        <el-table-column label="报告文号" prop="reportId" width="170px" />
        <el-table-column label="报告名称" prop="reportName" width="300px" :formatter="subName" />
        <el-table-column label="评估价值" prop="assessValue" />
        <el-table-column label="评估日期" prop="valuationDate" :formatter="tableTimeFormat" />
        <el-table-column label="出具日期" prop="provideDate" :formatter="tableTimeFormat" />
        <el-table-column label="业务人员" prop="salesman" />
        <el-table-column label="技术人员" prop="technician" />
      </el-table>
      <el-pagination
        :current-page="currentPage"
        :page-sizes="[10, 20, 40, 80]"
        :page-size="sizePage"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalPage"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-main>
  </el-container>
</template>

<script>
import { searchEnquiryProperty, getSearchFormList } from '@/api/property-report'
import { ellipsisString, parseTime } from '@/utils'

export default {
  name: 'Index',
  data() {
    return {
      searchObj: {},
      propertyType: [],
      propertyProjectType: [],
      leaf: [],
      users: [],
      propertyList: [],
      currentPage: 1,
      sizePage: 10,
      totalPage: 0
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      this.getPropertyList()
      this.getSearchForm()
    },

    getPropertyList() {
      const currentPage = this.currentPage
      const sizePage = this.sizePage
      const searchObj = this.searchObj
      searchEnquiryProperty(searchObj, currentPage, sizePage).then(res => {
        this.propertyList = res.data.list
        this.totalPage = res.data.total
      })
    },
    clearSearch() {
      this.searchObj = {}
      this.getPropertyList()
      // 重置成功提示框
      this.$message({
        message: '重置成功',
        type: 'success'
      })
    },
    subName(row, column, cellValue, index) {
      return ellipsisString(cellValue)
    },
    getSearchForm() {
      getSearchFormList().then(res => {
        this.propertyType = res.data.propertyType
        this.propertyProjectType = res.data.propertyProjectType
        this.leaf = res.data.leaf
        this.users = res.data.users
      })
    },
    handleSizeChange(val) {
      this.sizePage = val
      this.getPropertyList()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.getPropertyList()
    },
    tableTimeFormat(row, column, cellValue, index) {
      return parseTime(cellValue, '')
    }

  }
}
</script>

<style scoped>

</style>
